package access.impl;

import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import access.AccessDao;

public class AccessDaoImpl extends HibernateDaoSupport implements AccessDao {

	@Override
	public boolean accessAction(int userId, int actionId) {
		Query q = getSession().createQuery("");
		q.setInteger(0, userId);
		q.setInteger(1, actionId);
		
		Integer count = (Integer) q.uniqueResult();
		
		if(count != null && count == 1) {
			return true;
		}
		
		return false;
	}

	@Override
	public boolean accessRole(int userId, int roleId) {
		Query q = getSession().createQuery("");
		q.setInteger(0, userId);
		q.setInteger(1, roleId);
		
		Integer count = (Integer) q.uniqueResult();
		
		if(count != null && count == 1) {
			return true;
		}
		
		return false;
	}
}
